#!/bin/bash

if [ -n "$1" ]; then
    data_date=$1
else
  data_date=`date -d '-1 days' +%F`
fi
dim_vivo_app_info="
WITH a AS (
    SELECT
        *
    FROM vivo_app_warehouse.vivo_device_info
    WHERE dt = '${data_date}'
),b AS (
    SELECT
        *
    FROM vivo_app_warehouse.vivo_user_info
    WHERE dt = '${data_date}'
)
INSERT OVERWRITE TABLE vivo_app_warehouse.dim_vivo_app_info PARTITION (dt = '${data_date}')
SELECT
    a.device_id,
    b.user_id,
    b.register_date,
    b.first_login_date,
    b.last_login_date,
    b.is_active,
    a.device_type,
    a.device_model,
    a.manufacture_date,
    a.purchase_date,
    a.screen_size,
    a.resolution,
    a.memory_size,
    a.storage_size,
    a.os_type,
    a.os_version,
    a.network_type,
    a.is_rooted,
    a.update_time
FROM a
LEFT JOIN b ON a.user_id = b.user_id;
"
/opt/module/spark/bin/beeline -u jdbc:hive2://node101:10001 -n bwie -e "
${dim_vivo_app_info}
"